package com.domino.server;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.logging.Logger;

import com.domino.client.AdminService;
import com.domino.server.cache.BoardCache;
import com.domino.server.cache.BoardCacheImpl;
import com.domino.server.cache.GameSessionData;
import com.domino.server.persistence.gamesession.BoardDao;
import com.domino.server.persistence.gamesession.BoardDaoImpl;
import com.domino.server.persistence.gamesession.GameSessionDao;
import com.domino.server.persistence.gamesession.GameSessionDaoImpl;
import com.google.gwt.user.server.rpc.RemoteServiceServlet;

public class AdminServiceImpl extends RemoteServiceServlet implements
		AdminService {
	
	Logger LOG = Logger.getLogger(getClass().getCanonicalName());
	
	private GameSessionDao gsdDao;
	private BoardDao boardDao;
	private BoardCache boardCache;
	
	public AdminServiceImpl() {
		gsdDao = new GameSessionDaoImpl();
		boardDao = new BoardDaoImpl();
		boardCache = new BoardCacheImpl(gsdDao, boardDao);
	}


	@Override
	public List<String> getSessionInfo(Date from, Date to)
			throws IllegalArgumentException {
		List<GameSessionData> gsds = gsdDao.findByDateTimeIntervall(from,to, 100);
		return toListString(gsds);
	}
	
	private List<String> toListString(List<GameSessionData> gsds) {
		List<String> res = new ArrayList<String>(gsds.size());
		for (GameSessionData gsd : gsds) {
			res.add(toString(gsd));
		}
		return res;
	}
	
	private String toString(GameSessionData gsd) {
		return gsd.toString();
	}


}
